{include file='common/head.html'}
<style>
	html,body,.layui-body {
		height: 100%;
	}
</style>
<script type="text/javascript" src="{APP_THEME_DIR}/layui/layui.all.js?v=v2.5.4"></script>
<script type="text/javascript" src="{APP_THEME_DIR}/js/jquery.dragsort-0.5.2.min.js"></script>
<div class="layui-body">

	{if([$list])}
	<div class="layui-tab layui-tab-brief" lay-filter="tab">
	  <ul class="layui-tab-title">
	    <li class="layui-this" lay-id="t1">标签内容</li>
		{if(session('ucode')==10001)}
	    <li lay-id="t2">标签管理</li>
	    <li lay-id="t3">新增标签</li>
		{/if}
	  </ul>
	  <div class="layui-tab-content">
	  	<div class="layui-tab-item layui-show">
	  		<form action="{url./admin/Label/index}" method="post" class="layui-form">
	  			<input type="hidden" name="formcheck" value="{$formcheck}" > 
	  			{foreach $labels(key,value)}
	  				{if($value->type==1)} <!-- 文本 -->
		                <div class="layui-form-item">
		                     <label class="layui-form-label">[value->description]</label>
		                     <div class="layui-input-block">
		                     	<input type="text" name="[value->name]" value="[value->value]" placeholder="请输入[value->description]"  class="layui-input">
		                     </div>
		                </div>
	                {/if}
	                
	                {if($value->type==2)}<!-- 日期 -->
	                	 <div class="layui-form-item">
		                     <label class="layui-form-label">[value->description]</label>
		                     <div class="layui-input-block">
		                     	<input type="text" name="[value->name]" readonly value="[value->value]" placeholder="请选择[value->description]"  class="layui-input datetime">
		                     </div>
		                </div>
	                {/if}
	                
	                {if($value->type==3)}<!-- 图片 -->
	                	<div class="layui-form-item">
		                     <label class="layui-form-label">[value->description]</label>
		                     <div class="layui-input-inline">
		                     	<input type="text" name="[value->name]" id="[value->name]" value="[value->value]" placeholder="请上传[value->description]"  class="layui-input">
		                     </div>
		                     <button type="button" class="layui-btn upload layui-btn-primary" data-des="[value->name]">
							 	 <i class="layui-icon">&#xe67c;</i>上传图片
							 </button>
                             <a class="layui-btn layui-btn-warm" onclick="GetPictureFolder(1,'[value->name]');"><i class="layui-icon">&#xe64a;</i>图库</a>
							 <div id="[value->name]_box" class="pic">{if($value->value)}<dl><dt><img src="{SITE_DIR}[value->value]" data-url="[value->value]"></dt><dd>删除</dd></dl>{/if}</div>
		                </div>
	                {/if}

	                {if($value->type==8)}<!-- 多图文@mk-label -->
		                <div class="layui-form-item">
		                    <label class="layui-form-label">[value->description]</label>
		                    <input type="hidden" name="[value->name]" value="[value->value]" class="layui-input">
		                    <div class="layui-input-block">
		                        <fieldset class="layui-elem-field">
		                            <div class="layui-field-box">
		                                <div class="images_upload_wrap" id="[value->name]">
		                                    <li class='placeHolder' style="display: none;"><div></div></li>
		                                    {php}
		                                    if($value->value){
		                                        $image_text=unserialize($value->value);
		                                    }else{
		                                        $image_text = array();
		                                    }
		                                    foreach ($image_text as $key=>$value2) {
		                                        echo "<li class='images_li'><div class='images_upload ui-sortable-handle'><div class='ic'><div class='upimg'><div class='icaction'><span class='load_images mr5 j_upload_".$value->name."' id='js_upload_".$value->name."_".$key."'><i class='fa fa-photo'></i>更换图片</span></div><div class='cover-bg'></div><img class='imgshow'src='".$value2[src]."'></div><span class='span_input'><input type='hidden'class='imghide'name='img_litpic_".$value->name."[]'value='".$value2[src]."'></span><input type='text'name='img_title_".$value->name."[]'placeholder='标题'class='layui-input' value='".$value2[title]."'></input><textarea name='img_intro_".$value->name."[]'placeholder='描述'class='layui-textarea'>".$value2[intro]."</textarea><div class='operation'><a href='javascript:void(0);'><i class='fa fa-remove'></i>删除</a></div></div></div></li>";
		                                    }
		                                    {/php}
		                                </div>
		                                <button type="button" class="layui-btn layui-btn-sm addpic_[value->name]" style="margin-top: 5px;">新增</button>
		                                <script>
		                                      $('.images_upload_wrap').on("click",'.operation a',function(){
		                                          $(this).parents().parents().parents('.images_upload').parents(".images_li").remove();
		                                      });
		                                </script>
		                                <script type="text/javascript">
		                                $("#[value->name]").dragsort({
		                                    dragSelector: "li",
		                                    dragBetween: false,
		                                    dragSelectorExclude: "input,textarea,.load_images",
		                                    dragEnd: saveOrder_images_upload_[value->name],
		                                    placeHolderTemplate: "<li class='placeHolder'><div></div></li>"
		                                });
		                                function saveOrder_images_upload_[value->name]() {
		                                    console.log('ok');
		                                };
		                                </script>
		                            </div>
		                        </fieldset>
		                    </div>
		                </div>
		                <script>
		                	layui.use(['upload'], function() {
		                		var sitedir_[value->name]=$('#sitedir').data('sitedir');
		                	    var upload_[value->name] = layui.upload;
		                	    picDescUpload_[value->name]('#[value->name]');
		                	    function picDescUpload_[value->name](ele_id) {
		                	        var c_num = $(ele_id).children().length;
		                	        var uploadurl = $("#preurl").data('preurl')+'/index/upload';
		                	        $('.addpic_[value->name]').click(function() {
		                	            var newpic = '<li class="images_li"><div class="images_upload ui-sortable-handle"><div class="ic"><div class="upimg"><div class="icaction"><span class="load_images mr5 js-upload" id="js_upload_[value->name]_' + c_num + '"><i class="fa fa-photo"></i>更换图片</span></div><div class="cover-bg"></div><img class="imgshow"src="/static/images/nopic.png"></div><span class="span_input"><input type="hidden"class="imghide"name="img_litpic_[value->name][]"value=""></span><input type="text"name="img_title_[value->name][]"placeholder="标题"class="layui-input"></input><textarea name="img_intro_[value->name][]"placeholder="描述"class="layui-textarea"></textarea><div class="operation"><a href="javascript:void(0);"><i class="fa fa-remove"></i>删除</a></div></div></div></li>';
		                	            var ele_upload = '#js_upload_[value->name]_' + c_num;
		                	            c_num++;
		                	            $(ele_id).append(newpic);
		                	            var uploadInst2 = upload_[value->name].render({
		                	                elem: ele_upload //绑定元素
		                	                    ,
		                	                url: uploadurl //上传接口
		                	                    ,
		                	                field: 'upload' //字段名称
		                	                    ,
		                	                multiple: false //多文件上传
		                	                    ,
		                	                accept: 'images' //接收文件类型 images（图片）、file（所有文件）、video（视频）、audio（音频）
		                	                    ,
		                	                acceptMime: 'image/*',
		                	                before: function(obj) {
		                	                    //判断是否需要加水印
		                	                    if ($(this.item).hasClass('watermark')) {
		                	                        uploadInst2.config.url = uploadurl + '/watermark/1'; //改变URL
		                	                    }
		                	                    layer.load(); //上传loading
		                	                },
		                	                done: function(res) {
		                	                    var item = this.item;
		                	                    var des = $(item).data('des');
		                	                    layer.closeAll('loading'); //关闭loading
		                	                    if (res.code == 1) {
		                	                        // console.log(res.data[0]);
		                	                        item.parent().parent().siblings(".span_input").find(".imghide").val(res.data[0]);
		                	                        item.parent().siblings(".imgshow").attr("src", sitedir_[value->name] + res.data[0]);
		                	                        layer.msg('上传成功！');
		                	                    } else {
		                	                        layer.msg('上传失败：' + res.data);
		                	                    }
		                	                },
		                	                error: function() {
		                	                    layer.closeAll('loading'); //关闭loading
		                	                    layer.msg('上传发生错误!');
		                	                }
		                	            });
		                	        })
		                	        var uploadInst_[value->name] = upload_[value->name].render({
		                	            elem: '.j_upload_[value->name]' //绑定元素
		                	                ,
		                	            url: uploadurl //上传接口
		                	                ,
		                	            field: 'upload' //字段名称
		                	                ,
		                	            multiple: false //多文件上传
		                	                ,
		                	            accept: 'images' //接收文件类型 images（图片）、file（所有文件）、video（视频）、audio（音频）
		                	                ,
		                	            acceptMime: 'image/*',
		                	            before: function(obj) {
		                	                //判断是否需要加水印
		                	                if ($(this.item).hasClass('watermark')) {
		                	                    uploadInst_[value->name].config.url = uploadurl + '/watermark/1'; //改变URL
		                	                }
		                	                layer.load(); //上传loading
		                	            },
		                	            done: function(res) {
		                	                var item = this.item;
		                	                var des = $(item).data('des');
		                	                layer.closeAll('loading'); //关闭loading
		                	                if (res.code == 1) {
		                	                    // console.log(res.data[0]);
		                	                    item.parent().parent().siblings(".span_input").find(".imghide").val(res.data[0]);
		                	                    item.parent().siblings(".imgshow").attr("src", sitedir_[value->name] + res.data[0]);
		                	                    layer.msg('上传成功！');
		                	                } else {
		                	                    layer.msg('上传失败：' + res.data);
		                	                }
		                	            },
		                	            error: function() {
		                	                layer.closeAll('loading'); //关闭loading
		                	                layer.msg('上传发生错误!');
		                	            }
		                	        });
		                	    }
		                	})
		                </script>
	                {/if}
	                
	                {if($value->type==4)}<!-- 文件 -->
	                	<div class="layui-form-item">
		                     <label class="layui-form-label">[value->description]</label>
		                     <div class="layui-input-inline">
		                     	<input type="text" name="[value->name]" id="[value->name]" value="[value->value]" placeholder="请上传[value->description]"  class="layui-input">
		                     </div>
		                     <button type="button" class="layui-btn file layui-btn-primary" data-des="[value->name]">
							 	 <i class="layui-icon">&#xe67c;</i>上传文件
							 </button>
		                </div>
	                {/if}
	                
	                {if($value->type==5)}<!-- 编辑器 -->
	                	<div class="layui-form-item">
		                     <label class="layui-form-label">[value->description]</label>
		                     <div class="layui-input-block">
		                     	<script type="text/plain" id="[value->name]" name="[value->name]" style="width:100%;height:240px;">{fun=decode_string($value->value)}</script>
		                     </div>
		                </div>
		                <script>
							//初始化编辑器
							$(document).ready(function (e) {
								var ue = UE.getEditor('[value->name]',{
									maximumWords:500 
								});
							})
						</script>
	                {/if}
	                
	                {if($value->type==6)} <!-- 开关 -->
		                <div class="layui-form-item">
		                     <label class="layui-form-label">[value->description]</label>
		                     <div class="layui-input-block">
		                     	<input type="radio" name="[value->name]" value="1" title="开启" {if($value->value)}checked{/if}>
      							<input type="radio" name="[value->name]" value="0" title="关闭" {if(!$value->value)}checked{/if}>
		                     </div>
		                </div>
	                {/if}
	                
	                {if($value->type==7)} <!-- 多行文本 -->
		                <div class="layui-form-item">
		                     <label class="layui-form-label">[value->description]</label>
		                     <div class="layui-input-block">
		                     	<textarea name="[value->name]" class="layui-textarea" placeholder="请输入[value->description]">{fun=str_replace("<br>","\r\n",html_entity_decode($value->value))}</textarea>
		                     </div>
		                </div>
	                {/if}
	                
	  			{/foreach}
	  			<div class="layui-form-item">
					 <div class="layui-input-block">
					    <button class="layui-btn" lay-submit>立即提交</button>
					    <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
					 </div>
				</div>
	  		</form>
	  	</div>
	  	{if(session('ucode')==10001)}
	  	<div class="layui-tab-item">
	  		<form action="{url./admin/Label/index}" method="post" class="layui-form">
	  			<input type="hidden" name="formcheck" value="{$formcheck}" > 
		  		<table class="layui-table mt0">
	            	<thead>
	                    <tr>
	                        <th width="60px">排序</th>
	                        <th width="40px">ID</th>
	                        <th>名称</th>
	                        <th>描述</th>
	                        <th>类型</th>
	                        <th>添加人员</th>
	                        <th>修改人员</th>
	                        <th>添加时间</th>
	                        <th>修改时间</th>
	                        <th>操作</th>
	                    </tr>
	        		</thead>
	                <tbody>
	                {foreach $labels(key,value,num)}
	                    <tr>
	                    	<td class="table-input">
	                    	    <input type="hidden" name="listall[]" value="[value->id]">
	                    	    <input type="text" lay-ignore class="layui-input" name="sorting[]" value="[value->sorting]">
	                    	</td>
	                        <td>[value->id]</td>
	                        <td>[value->name]</td>
	                        <td>[value->description]</td>
	                        <td>
	                        {if($value->type==1)}单行文本{/if}
	                        {if($value->type==7)}多行文本{/if}
	                        {if($value->type==2)}时间{/if}
	                        {if($value->type==3)}图片{/if}
	                        {if($value->type==8)}多图文{/if}
	                        {if($value->type==4)}附件{/if}
	                        {if($value->type==5)}编辑器{/if}
	                        {if($value->type==6)}开关{/if}
	                        </td>
	                        <td>[value->create_user]</td>
	                        <td>[value->update_user]</td>
	                        <td>[value->create_time]</td>
	                        <td>[value->update_time]</td>
	                        <td>
	                        	{fun=get_btn_mod($value->id)}
	                            {fun=get_btn_del($value->id)}
								<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary [value->name]" onclick="showtext('[value->name]');" data-clipboard-text="{label:[value->name]}">标签调用</a>
	                        </td>
	                    </tr>
	                {/foreach}
	                </tbody>

	            </table>
	            <button type="submit" name="submit" value="sorting" class="layui-btn layui-btn-sm">保存排序</button>
	        </form>
	  	</div>
	  	
	  	<div class="layui-tab-item">
	  		 <form action="{url./admin/Label/add}" method="post" class="layui-form">
	  		 	<input type="hidden" name="formcheck" value="{$formcheck}" > 
	  		 	<div class="layui-form-item">
                     <label class="layui-form-label">标签名称</label>
                     <div class="layui-input-block">
                     	<input type="text" name="name" required  lay-verify="required" placeholder="请输入标签名称"  class="layui-input">
                     	<div class="layui-form-mid layui-word-aux">只能含有字母、数字、下划线</div>
                     </div>
                     
                </div>
                
                <div class="layui-form-item">
                     <label class="layui-form-label">标签描述</label>
                     <div class="layui-input-block">
                     	<input type="text" name="description" required  lay-verify="required" placeholder="请输入标签描述"  class="layui-input">
                     </div>
                </div>
                
                <div class="layui-form-item">
                     <label class="layui-form-label">标签类型</label>
                     <div class="layui-input-block">
                     	<select name="type" lay-verify="required">
	                    	<option value="1">单行文本</option>
	                    	<option value="7">多行文本</option>
	                    	<option value="2">时间</option>
	                    	<option value="3">图片</option>
	                    	<option value="8">多图文</option>
	                    	<option value="4">附件</option>
	                    	<option value="5">编辑器</option>
	                    	<option value="6">开关</option>
	                    </select>
                     </div>
                </div>
                
                <div class="layui-form-item">
					 <div class="layui-input-block">
					    <button class="layui-btn" lay-submit>立即提交</button>
					    <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
					 </div>
				</div>
	  		 </form>
	  	</div>
		{/if}
	  	
	  </div>
	</div>
	{/if} 
	
	
	{if([$mod])}
	
	<div class="layui-tab layui-tab-brief" lay-filter="tab">
	  <ul class="layui-tab-title">
	    <li class="layui-this">标签修改</li>
	  </ul>
	  <div class="layui-tab-content">
	  	<div class="layui-tab-item layui-show">
	  		  <form action="{url./admin/Label/mod/id/'.[$get.id].'}{$backurl}" method="post" class="layui-form">
	  		  	<input type="hidden" name="formcheck" value="{$formcheck}" > 
	  		  	<div class="layui-form-item">
                     <label class="layui-form-label">标签名称</label>
                     <div class="layui-input-block">
                     	<input type="text" name="name" required  lay-verify="required" value="{$label->name}"  placeholder="请输入标签名称"  class="layui-input">
                     	<div class="layui-form-mid layui-word-aux">只能含有字母、数字、下划线</div>
                     </div>
                     
                </div>
                
                <div class="layui-form-item">
                     <label class="layui-form-label">标签描述</label>
                     <div class="layui-input-block">
                     	<input type="text" name="description" required  lay-verify="required"  value="{$label->description}" placeholder="请输入标签描述"  class="layui-input">
                     </div>
                </div>
                
                <div class="layui-form-item">
                     <label class="layui-form-label">标签类型</label>
                     <div class="layui-input-block">
                     	<select name="type" lay-verify="required">
	                    	<option value="1" {if([$label->type]==1)}selected{/if}>单行文本</option>
	                    	<option value="7" {if([$label->type]==7)}selected{/if}>多行文本</option>
	                    	<option value="2" {if([$label->type]==2)}selected{/if}>时间</option>
	                    	<option value="3" {if([$label->type]==3)}selected{/if}>图片</option>
	                    	<option value="8" {if([$label->type]==8)}selected{/if}>多图文</option>
	                    	<option value="4" {if([$label->type]==4)}selected{/if}>附件</option>
	                    	<option value="5" {if([$label->type]==5)}selected{/if}>编辑器</option>
	                    	<option value="6" {if([$label->type]==6)}selected{/if}>开关</option>
	                    </select>
                     </div>
                </div>
                
                <div class="layui-form-item">
					 <div class="layui-input-block">
					    <button class="layui-btn" lay-submit>立即提交</button>
					    <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
					    {fun=get_btn_back()}
					 </div>
				</div>
	  		  </form>
	  	</div>
	  </div>
	 </div>
	{/if}

</div>

{include file='common/ueditor.html'}
{include file='common/foot.html'}
